﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CUREDataAccessLayers;
using CUREEntity;
using System.Data;

/*************************************************************************************

     * 作   者： 张 颖
  
*************************************************************************************/
namespace CUREBusinessLogicLayer
{
    public class ModulBll
    {
        ModuleDal moduDal = new ModuleDal();
        /// <summary>
        /// 获取模块信息
        /// </summary>
        /// <returns></returns>
        public DataTable GetModuData()
        {
            DataTable dt = new DataTable();
            DataTable table = moduDal.GetActionColumnData();
            if (table != null && table.Rows.Count > 0)
            {
                dt = table;
            }
            return dt;
        }
        /// <summary>
        /// 获取子模块信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DataTable GetChildModuData(string id)
        {
            DataTable dt = new DataTable();
            DataTable table = moduDal.GetActionData(id);
            if (table != null && table.Rows.Count > 0)
            {
                dt = table;
            }
            return dt;
        }
        /// <summary>
        /// 获取模块
        /// </summary>
        /// <param name="fatherid"></param>
        /// <returns></returns>
        public DataTable GetChildModuleByfatherId(string fatherid)
        {
            DataTable dt = new DataTable();
            DataTable table = moduDal.GetChildModuleByfatherId(fatherid);
            if (table != null && table.Rows.Count > 0)
            {
                dt = table;
            }
            return dt;
        }
        /// <summary>
        /// 获取子模块
        /// </summary>
        /// <param name="chindname"></param>
        /// <returns></returns>
        public DataTable GetChildModuleById(string chindname)
        {
            DataTable dt = new DataTable();
            DataTable table = moduDal.GetChildModuleById(chindname);
            if (table != null && table.Rows.Count > 0)
            {
                dt = table;
            }
            return dt;
        }
        public bool InsertSuccess(string id, string name, string url, string father, string actionSort)
        {
            bool addSuccess = false;
            int result = moduDal.InsertModel(id, name, url, father, actionSort);
            if (result > 0)
            {
                addSuccess = true;
            }
            return addSuccess;
        }
        public bool UpdateScuccess(string id, string name, string url, string father, string actionSort)
        {
            bool updateSuccess = false;
            int result = moduDal.UpdateModel(id, name, url, father, actionSort);
            if (result > 0)
            {
                updateSuccess = true;
            }
            return updateSuccess;
        }
        public bool DelSuccess(string url)
        {
            bool delSuccess = false;
            int result = moduDal.DeleteModel(url);
            if (result > 0)
            {
                delSuccess = true;
            }
            return delSuccess;
        }

        public int GetMaxId()
        {
            int maxid = 0;
            decimal id = moduDal.getMaxId();
            if (id.ToString() != "" && id.ToString() != null)
            {
                maxid =Convert.ToInt32(id);
            }
            return maxid;
        }

        public bool SelectModelByurl(string id, string url)
        {
            bool exist = false;
            DataTable dt = moduDal.GetModelByurl(id, url);
            if (dt != null && dt.Rows.Count > 0)
            {
                exist = true;
            }
            return exist;
        }
        /// <summary>
        /// 获取上级模块
        /// </summary>
        /// <returns></returns>
        public DataTable GetFatherModel()
        {
            DataTable dt = new DataTable();
            DataTable table = moduDal.GetFatherModel();
            if (table != null && table.Rows.Count > 0)
            {
                dt = table;
            }
            return dt;
        }
        /// <summary>
        /// 根据id获取模块
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DataTable GetModelById(string id)
        {
            DataTable dt = new DataTable();
            DataTable table = moduDal.GetModelById(id);
            if (table != null && table.Rows.Count > 0)
            {
                dt = table;
            }
            return dt;
        }
    }
}
